% For "The Climate Risk Premium" (Lemoine, JAERE, 2020)

% Script that controls state variable transitions

M1change = Params.timestep*Params.M1_frac*bsxfun(@times, Params.em_per_cons(index_time-1+(index_interval*Params.timestep),Params.em_per_cons_declinerate), cons_value);
M2change = Params.timestep*Params.M2_frac*bsxfun(@times, Params.em_per_cons(index_time-1+(index_interval*Params.timestep),Params.em_per_cons_declinerate), cons_value) - Params.timestep*Params.co2_decay*M2_value;
forcing = Params.forcing*log((M1_value+M2_value)/Params.co2_preind);

if option_ocean
    tempchange = bsxfun( @plus, Params.timestep*(1/Params.Cupper)*( forcing - bsxfun(@times,Params.warming,temp_value) - Params.oceanxfer*( temp_value - oceantemp_value ) ) , ...
        bsxfun(@times, Params.temp_vol, Wiener.temp_increment(:,counter_fine) ) );
    oceantempchange = Params.timestep*(1/Params.Cdeep)*Params.oceanxfer*( temp_value - oceantemp_value );
else
    tempchange = bsxfun( @plus, Params.timestep*Params.inertia*( forcing - bsxfun(@times,Params.warming,temp_value) ) , ...
        bsxfun(@times, Params.temp_vol, Wiener.temp_increment(:,counter_fine) ) );
end

switch option_damagetype
    case 'base'
        conschange = cons_value.*( bsxfun (@plus, bsxfun(@times, -Params.timestep*Params.cons_damage, (temp_value-Params.dam_temp) ) , ...
            bsxfun(@plus, Params.timestep*Params.cons_drift(index_time-1+(index_interval*Params.timestep)), bsxfun(@times, Params.cons_vol, Wiener.cons_increment(:,counter_fine) ) ) ) );
    otherwise
        conschange = cons_value.*( bsxfun(@plus, Params.timestep*Params.cons_drift(index_time-1+(index_interval*Params.timestep)), bsxfun(@times, Params.cons_vol, Wiener.cons_increment(:,counter_fine) ) ) );        
end